import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import HomeChare from "../views/home/homecharts.vue"
import Login from "../views/login/Login.vue"
import Register from "../views/register/Register.vue"
import { Message } from "element-ui"
const BankManagement = () => import('../components/bankManagement/BankManagement.vue')
const AddBank = () => import('../components/bankManagement/AddBank.vue')
const fundManagement = () => import('../components/fundManagement/fundManagement.vue')
const Addfund = () => import('../components/fundManagement/Addfund.vue')
const deletefund = () => import('../components/fundManagement/deletefund.vue')
const appCode = () => import('../components/appCode/appCode.vue')
const EditorFund = () => import('../components/fundManagement/EditorFund.vue')
const editorBank = () => import('../components/bankManagement/editorBank.vue')
// 员工
const PersonnelManage = () => import('../components/personnelManage/PersonnelManage.vue')
// 活期
const TerminalManage = () => import('../components/TerminalManage/TerminalManage.vue')


const DueOnDemand = () => import('../components/dueondemand/DueOnDemand.vue');
const addible = () => import('../components/dueondemand/addible.vue')
const RoleList = () => import('../components/role/RoleList.vue')
const RoleAdd = () =>import('../components/role/RoleAdd.vue')
const RoleUpdate = () =>import('../components/role/RoleUpdate.vue')
const SetRole = () =>import('../components/role/SetRole.vue')


Vue.use(VueRouter)

//解决路由重复问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  // 路由重定向
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    beforeEnter: async (to, from, next) => {
      const token = localStorage.token;
      if (token) {
        next();
      } else {
        Message.error('您还未登录，请登录')
        next('/login')
      }

    },
    children: [
      {
        path: '',
        component: HomeChare
      },
      // 优惠券管理
      {
        path: 'CouponManagement',
        name: 'CouponManagement',
        component: () => import('../components/CouponManagement/CouponManagementList.vue')
      },
      // 基金经理管理
      {
        path: "FundManagerManagement",
        name: "FundManagerManagement",
        component: () => import('../components/FundManagerManagement/FundManagerManagement.vue')
      },
      //新增优惠券
      {
        path: 'AddCouponManagementList',
        name: 'AddCouponManagementList',
        component: () => import('../components/CouponManagement/AddCouponManagementList.vue')
      },
      // 新增基金经理
      {
        path: 'AddFundManagerManagement',
        name: 'AddFundManagerManagement',
        component: () => import('../components/FundManagerManagement/AddFundManagerManagement.vue')
      },
      {
        path: 'bankmanagement',
        name: 'BankManagement',
        component: BankManagement
      },
      {
        path: 'addbank',
        name: "AddBank",
        component: AddBank
      },
      {
        path: 'fundmanagement',
        name: "fundManagement",
        component: fundManagement
      },
      {
        path: 'addfund',
        name: "Addfund",
        component: Addfund
      },
      {
        path: 'deletefund',
        name: "deletefund",
        component: deletefund
      },
      {
        path: 'appCode',
        name: "appCode",
        component: appCode
      },
      {
        path: 'editorfund/:id',
        props: true,
        name: "EditorFund",
        component: EditorFund
      },
      {
        path: 'editorbank/:id',
        props: true,
        name: "editorBank",
        component: editorBank
      },
      {
        path: 'goldManagement',
        name: 'GoldManagement',
        component: () => import('../components/goldManagement/GoldManagement.vue'),
      },
      {
        path: 'addGoldManagement',
        name: 'AddGoldManagement',
        component: () => import('../components/goldManagement/AddGoldManagement.vue'),
      },
      {
        path: 'recovery',
        name: 'Recovery',
        component: () => import('../components/goldManagement/Recovery.vue'),
      },
      {
        path: 'changeGoldManagement',
        name: 'ChangeGoldManagement',
        component: () => import('../components/goldManagement/ChangeGoldManagement.vue'),
      },
      {
        path: 'peopleOnline',
        name: 'PeopleOnline',
        component: () => import('../components/peopleOnline/PeopleOnline.vue'),
      },
      // 定期管理
      {
        path: "terminalManage",
        name: "TerminalManage",
        component: TerminalManage,
      },
      // 员工管理
      {
        path: "personnelManage",
        name: "PersonnelManage",
        component: PersonnelManage
      },
      {
        path: 'DueOnDemand',
        name: 'DueOnDemand',
        component: DueOnDemand
      },
      {
        path: 'addible',
        name: 'addible',
        component: addible
      },
      {
        path: 'RoleList',
        name: 'RoleList',
        component: RoleList
      },
      {
        path: 'RoleAdd',
        name: 'RoleAdd',
        component: RoleAdd
      },
      {
        path: 'RoleUpdate/:id?',
        name: 'RoleUpdate',
        component: RoleUpdate
      },
      {
        path: 'SetRole',
        name: 'SetRole',
        component: SetRole
      }
    ]
  },
  {
    path: '/login',
    component: Login,
  },
  {
    path: '/register',
    component: Register,
    path: '/',
    redirect: '/home'
  },

]

const router = new VueRouter({
  routes,
  mode: "history"   //更改模式
})

export default router
